cmake_minimum_required(VERSION 3.8)
project(costmap_2d)

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-sign-compare -Wno-deprecated-declarations)
endif()

add_compile_options(-g -O0)

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(laser_geometry REQUIRED)
find_package(map_msgs REQUIRED)
find_package(message_filters REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(nav2_voxel_grid REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)

find_package(Eigen3 REQUIRED)

include_directories(
  include
  ${EIGEN3_INCLUDE_DIRS}
)
add_definitions(${EIGEN3_DEFINITIONS})

set(dependencies
  rclcpp
  geometry_msgs
  laser_geometry
  map_msgs
  message_filters
  nav_msgs
  pluginlib
  sensor_msgs
  std_msgs
  tf2
  tf2_ros
  visualization_msgs
  nav2_voxel_grid
  tf2_geometry_msgs
  nav2_msgs
)

add_library(costmap_2d_core SHARED
  src/array_parser.cpp
  src/costmap_2d.cpp
  src/observation_buffer.cpp
  src/layer.cpp
  src/layered_costmap.cpp
  src/costmap_2d_ros.cpp
  src/costmap_2d_publisher.cpp
  src/costmap_math.cpp
  src/footprint.cpp
  src/costmap_layer.cpp
)
ament_target_dependencies(costmap_2d_core
  ${dependencies}
)

add_library(layers SHARED
  plugins/inflation_layer.cpp
  plugins/obstacle_layer.cpp
  plugins/static_layer.cpp
  plugins/voxel_layer.cpp
  src/observation_buffer.cpp
)
ament_target_dependencies(layers
  ${dependencies}
)
target_link_libraries(layers
  costmap_2d_core
)

add_executable(costmap_2d_markers src/costmap_2d_markers.cpp)
target_link_libraries(costmap_2d_markers
  costmap_2d_core
)
ament_target_dependencies(costmap_2d_markers
  ${dependencies}
)

add_executable(costmap_2d_cloud src/costmap_2d_cloud.cpp)
target_link_libraries(costmap_2d_cloud
  costmap_2d_core
)
ament_target_dependencies(costmap_2d_cloud
  ${dependencies}
)

add_executable(costmap_2d_node src/costmap_2d_node.cpp)
target_link_libraries(costmap_2d_node
  costmap_2d_core
  layers
)
ament_target_dependencies(costmap_2d_node
  ${dependencies}
)

install(TARGETS
  costmap_2d_core
  layers
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(TARGETS
  costmap_2d_node
  costmap_2d_markers
  costmap_2d_cloud
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include)
ament_export_libraries(layers costmap_2d_core)
ament_export_dependencies(${dependencies})
pluginlib_export_plugin_description_file(costmap_2d costmap_plugins.xml)

ament_package()
